﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SOWY.common;
namespace SOWY
{
    public partial class InputDialog : Form
    {
      
        private string input { get; set; }
        private string action;
        private InputDialog(string content, string action)
        {
            //this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 
            InitializeComponent();
            this.action = action;
            this.Text = action;
            lblTitle.Text = action;
           
            txtContent.Text = content;
            txtCommand.TabIndex = 0;
        }
        private void txtCommand_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                checkInput();
            }
            else if (e.KeyCode == Keys.Escape)
            {
                input = "";
                this.Close();
            }
        }

        private void checkInput()
        {
            string command = txtCommand.Text.ToLower().Trim();
            if (command.Length == 0)
            {
                MessageBox.Show("Please enter the index of task you wish to " + action + ", or click \"cancel\" to exit.","information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                input = command.Trim();
                this.Close();
            }
        }

        private void picCancel_Click(object sender, EventArgs e)
        {
            input = "";
            this.Close();
        }

        public static string show(List<Task> tasks, string action)
        {
            GUILogic objGUILogic = GUILogic.getInstance(); 
            string content = "";
            for (int i = 0; i < tasks.Count; i++)
            {
                content += (i + 1) + ".  " + objGUILogic.processTask(tasks[i]) + "\n";
            }
            InputDialog inputBox = new InputDialog(content, action);
            inputBox.ShowDialog();
            return inputBox.input;
        }

        public static string show(string content, string action)
        {            
            InputDialog inputBox = new InputDialog(content, action);
            inputBox.ShowDialog();
            return inputBox.input;
        }

        private void picOK_Click(object sender, EventArgs e)
        {
            checkInput();   
        }


        private void InputDialog_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                input = "";
                this.Close();
            }
        }

        private void InputDialog_Load(object sender, EventArgs e)
        {
        }

    }
}
